/**
 * 上传申请信息
 */
Ext.namespace('Ext.ux.wf');

Ext.ux.wf.csslljUpload = Ext.extend(Ext.Window, {
	title : '导入附件',
	layout: 'border',
	width: 380,
	spanid:'',
	attachname:'',
	height: 120,
	plain: true,
	modal: true,
	templateCode: null,
	formPanel: null,
	initComponent: function(){
		this.buttons =  [{
			text: '导入',
			handler: this.upload,
			scale: 'medium',
			iconCls: 'icon-middle-save',
			scope: this
		},{
			text: '取消',
			width: 90,
			iconCls: 'icon-middle-cancel',
			scale: 'medium',
			handler: this.closeWindow,
			scope: this
		}];
		Ext.ux.wf.csslljUpload.superclass.initComponent.call(this);
		
		var formPanel = new Ext.form.FormPanel({
			fileUpload: true,	//以附件上传的方式，相当于jsp中的表单中设置 method ="POST" enctype ="multipart/form-data" 
			url: this.url,
			region: 'center',
			frame: true,
			labelWidth: 85,
			labelAlign: 'right',
			items:[{
		xtype:'textfield',
		name:'file',
		inputType:'file',
		fieldLabel:'附件'
		}]
		});
		
		this.add(formPanel);
		this.formPanel = formPanel;
		
		
	},
	upload:function(){	
		var attache = dwr.util.getValue('file');
		if (attache.value == '') { 
		   Ext.Msg.alert("提示!","请选择附件!");
		   return;
		 }
		 var filename="";
		if(attache!=null){
		    filename = attache.value.substring(attache.value.lastIndexOf(".") + 1, attache.value.length);
		}
		obj ={
		  filename:filename
		};	
		var params=Ext.encode(obj);
		CsshljCntl.updateFile(params,attache, function(result){
			var jsonData =eval('('+result+')');
			var path="";
			var filetype="";
			for(var key in jsonData){
				if(key=="path"){
				  path=jsonData[key];
				}else if(key=="filename"){
				  filetype=jsonData[key];
				}
			}
			window.setFileValue(path,filetype);
		});
	},
	closeWindow: function(){
		this.close();
	}

});
